package com.leyou.item.dto;

import com.leyou.dto.BaseDTO;
import com.leyou.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ：qcq
 * @date ：Created in 2020/12/5 11:05
 * @description：
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class BrandDTO extends BaseDTO {

    private Long id;//品牌ID
    private String name;//品牌名称
    private String image;//品牌LOGO
    private char letter;//品牌首字母
    private List<Integer> categoryIds;//品牌相关的分类ID的集合

    public BrandDTO(BaseEntity entity) {
        super(entity);
    }

    /**
     * 将PO集合转为DTO集合
     * @param list PO对象的集合
     * @param <T> PO的类型
     * @return DTO集合
     */
    public static <T extends BaseEntity> List<BrandDTO> convertEntityList(Collection<T> list){
        if(list == null){
            return Collections.emptyList();
        }
        return list.stream().map(BrandDTO::new).collect(Collectors.toList());
    }

}
